
rem
bbdoc: Manages resources.
about: This manager is not instantiated.
endrem
Type TResources

	Global _resources:TMap = New TMap
	
	
	'cleans up all resources
	Function Free()
		_resources = Null
	End Function
	
		
	rem
	bbdoc: Adds a new group to the manager.
	returns: TMap
	endrem
	Function AddGroup:TMap(groupName:String)
		Local m:TMap = New TMap
		_resources.Insert(groupName, m)
		Return m
	End Function
	
	
	rem
	bbdoc: Retrieves a group from the manager.
	returns: TMap
	endrem
	Function GetGroup:TMap(groupName:String)
		Return TMap(_resources.ValueForKey(groupName))
	End Function
	
	
	rem
	bbdoc: Gets an object from the manager.
	endrem
	Function GetObject:Object(objectName:String, groupName:String = "")
		If groupName = "" Then groupName = "default"
		Local map:TMap = GetGroup(groupName)
		If map Then Return map.ValueForKey(objectName)
	End Function

	
	rem
	bbdoc: Stores object in the manager.
	about: Creates the group if needed.
	endrem
	Function StoreObject(o:Object, objectName:String, groupName:String = "")
		If o = Null Then RuntimeError("object is null!")
		If groupName = "" Then groupName = "default"
		
		Local map:TMap = GetGroup(groupName)
		If Not map Then map = AddGroup(groupName)
		map.Insert(objectName, o)
	End Function
	
	
	rem
	bbdoc: Stores image in the manager.
	about: Creates the group if needed.
	endrem
	Function StoreImage(image:TImage, imageName:String, groupName:String = "")
		If image = Null Then RuntimeError("Image '" + imageName + "' is null!")
		If groupName = "" Then groupName = "default"
		
		Local map:TMap = GetGroup(groupName)
		If Not map Then map = AddGroup(groupName)
		map.Insert(imageName, image)
	End Function
	
	
	rem
	bbdoc: Gets an image from the manager.
	endrem
	Function GetImage:TImage(imageName:String, groupName:String = "")
		If groupName = "" Then groupName = "default"
		Local map:TMap = GetGroup(groupName)
		If map Then Return TImage(map.ValueForKey(imageName))
	End Function
	
	
	rem
	bbdoc: Stores sound in the manager.
	about: Creates the group if needed.
	endrem
	Function StoreSound(sound:TSound, soundName:String, groupName:String = "")
		If sound = Null Then RuntimeError("Sound is null!")
		If groupName = "" Then groupName = "default"
		Local map:TMap = GetGroup(groupName)
		If Not map Then map = AddGroup(groupName)
		map.Insert(soundName, sound)
	End Function
	
	
	rem
	bbdoc: Gets sound from the manager.
	endrem
	Function GetSound:TSound(soundName:String, groupName:String = "")
		If groupName = "" Then groupName = "default"
		Local map:TMap = GetGroup(groupName)
		If map Then Return TSound(map.ValueForKey(soundName))
	End Function
	
	
End Type
